package com.example.musicplayer.dialogTools;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.example.musicplayer.R;
import com.example.musicplayer.musicTools.MusicSortType;

//选择歌曲排序方式的对话框
public class SortMusicDialog extends BaseDialog {
    private View mSortDefault;
    private View mSortDefaultReverse;
    private View mSortTitle;
    private View mSortArtist;
    private View mSortListenCounts;
    private View mCancel;

    public SortMusicDialog(Context context, MusicSortType mCurrentSortType) {
        super(context, R.style.NormalDialogStyle_Bottom);
        View imageView = null;
        View view = getDialogView();
        switch (mCurrentSortType) {
            case SORT_DEFAULT_REVERSE:
                if ((imageView = view.findViewById(R.id.imageview_default_reverse)) != null)
                    imageView.setVisibility(View.VISIBLE);
                break;
            case SORT_TITLE:
                if ((imageView = view.findViewById(R.id.imageview_title)) != null)
                    imageView.setVisibility(View.VISIBLE);
                break;
            case SORT_ARTIST:
                if ((imageView = view.findViewById(R.id.imageview_artist)) != null)
                    imageView.setVisibility(View.VISIBLE);
                break;
            case SORT_LISTEN_COUNTS:
                if ((imageView = view.findViewById(R.id.imageview_listen_counts)) != null)
                    imageView.setVisibility(View.VISIBLE);
                break;
            case SORT_DEFAULT:
            default:
                if ((imageView = view.findViewById(R.id.imageview_default)) != null)
                    imageView.setVisibility(View.VISIBLE);
                break;
        }
    }

    public View getSortDefault() {
        return mSortDefault;
    }

    public View getSortDefaultReverse() {
        return mSortDefaultReverse;
    }

    public View getSortTitle() {
        return mSortTitle;
    }

    public View getSortArtist() {
        return mSortArtist;
    }

    public View getSortListenCounts() {
        return mSortListenCounts;
    }

    public View getCancel() {
        return mCancel;
    }

    @Override
    protected View setDialogView(Context context) {
        View view = View.inflate(context, R.layout.dialog_sort_music, null);
        mSortDefault = view.findViewById(R.id.sort_as_default);
        mSortDefaultReverse = view.findViewById(R.id.sort_as_default_reverse);
        mSortTitle = view.findViewById(R.id.sort_as_title);
        mSortArtist = view.findViewById(R.id.sort_as_artist);
        mSortListenCounts = view.findViewById(R.id.sort_as_listen_counts);
        mCancel = view.findViewById(R.id.dialog_sort_music_cancel);
        return view;
    }

    @Override
    protected void setDialogLayout(Context context) {
        Window dialogWindow = mDialog.getWindow();
        if (dialogWindow != null) {
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = (int) context.getResources().getDimension(R.dimen.dialog_sort_music_height);
            lp.gravity = Gravity.BOTTOM;
            dialogWindow.setAttributes(lp);
        }
    }
}